package org.accp.baodan.zfb;

import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.domain.AlipayTradeWapPayModel;
import com.alipay.api.request.AlipayTradeCancelRequest;
import com.alipay.api.request.AlipayTradeWapPayRequest;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@CrossOrigin(methods= {RequestMethod.POST,RequestMethod.GET})
@RestController
public class Zfbweb {
    @RequestMapping("/Pay")
    public String Pay(String out_trade_no, String subject,String total_amount,String body,String timeout_express,String product_code) throws AlipayApiException {
        System.out.println("jdsfa");
//        out_trade_no="1234";
//        subject="毛毛鱼";
//        total_amount="1234";
//        body="很好吃";
//        timeout_express="20m";
//        product_code="212";
        AlipayConfig alipayConfig =new AlipayConfig();
        AlipayClient alipayClient=new DefaultAlipayClient(AlipayConfig.URL,AlipayConfig.APPID,AlipayConfig.RSA_PRIVATE_KEY,AlipayConfig.FORMAT,AlipayConfig.CHARSET,AlipayConfig.ALIPAY_PUBLIC_KEY,AlipayConfig.SIGNTYPE);
        AlipayTradeWapPayRequest request=new AlipayTradeWapPayRequest();
        AlipayTradeWapPayModel model=new AlipayTradeWapPayModel();
        model.setOutTradeNo(out_trade_no);
        model.setSubject(subject);
        model.setTotalAmount(total_amount);
        model.setBody(body);
        model.setTimeoutExpress(timeout_express);
        model.setProductCode(product_code);
        request.setBizModel(model);
        request.setNotifyUrl(AlipayConfig.notify_url);
        request.setReturnUrl(AlipayConfig.return_url);
        String form=alipayClient.pageExecute(request).getBody();
        System.out.println(form);
        return form;
    }
}
